﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Security.Cryptography;
using System.IO;

namespace Business.Crypto
{
    public static class HashingAlg
    {

        public static string GetHash(string text)
        {
            MD5CryptoServiceProvider md5Alg = CreateMD5Alg;
            
            byte[] bytes = Encoding.Unicode.GetBytes(text);
            byte[] encrypted = md5Alg.ComputeHash(bytes);

            return Convert.ToBase64String(encrypted);
        }
        public static string GetHash(FileStream streamFile)
        {
            MD5CryptoServiceProvider mdAlg = CreateMD5Alg;
            BinaryReader reader = new BinaryReader(streamFile);

            mdAlg.ComputeHash(reader.ReadBytes((int)streamFile.Length));
            return Convert.ToBase64String(mdAlg.Hash);

        }

        private static MD5CryptoServiceProvider CreateMD5Alg
        {
            get
            {
                MD5CryptoServiceProvider md5Alg = new MD5CryptoServiceProvider();
                return md5Alg;
            }
        }


    }
}
